
function formatobj(a){
let str = ""
for(key in a){
    str+= "&"+key+"="+a[key]
}
    str = str.slice(1)
    return str
}

const http = {

    get:function(url , date ,callback){
        let xhr = new XMLHttpRequest()
        xhr.open("get",url+"?"+formatobj(date))
        xhr.send()
        xhr.onreadystatechange = function(){
            if(xhr.readyState==4&&xhr.status==200){
               callback (JSON.parse(xhr.responseText))
            }
        }
    },

    post:function(url , date ,callback){
        let xhr = new XMLHttpRequest()
        xhr.open("post",url)
        xhr.setRequestHeader("content-type","application/JSON")
        xhr.send(JSON.stringify(date))
        xhr.onreadystatechange = function(){
            if(xhr.readyState==4&&xhr.status==200){
                callback(JSON.parse(xhr.responseText))
            }
        }
    },
    ajax:function(cs){
        if(cs.type=="get"){
            this.get(cs.url,cs.date,cs.success)
        }
        if(cs.type=="post"){
            this.post(cs.url,cs.date,cs.success)
        }
    }

}